package com.sf.webside.service;

import com.sf.webside.bean.SysRquestBean;
import com.sf.webside.config.Global;
import com.sf.webside.dao.CmsCategoryDao;
import com.sf.webside.dao.SysDictDao;
import com.sf.webside.entity.CmsCategoryEntity;
import com.sf.webside.vo.CmsCategoryVO;
import entity.PageVO;
import entity.ResultVO;
import entity.StatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import util.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tanjing on 2019/2/21.
 */
@Service
public class CmsCategoryService {
    private Logger logger= LoggerFactory.getLogger(CmsCategoryService.class);
    @Resource
    private Global global;
    @Autowired
    private CmsCategoryDao cmsCategoryDao;
    @Autowired
    private SysDictDao sysDictDao;

    /**
     * 获取栏目
     */
    public ResultVO list(String languageType){
        List<CmsCategoryEntity> cmsCategoryEntitieList = cmsCategoryDao.findByLanguageTypeAndDelFlagOrderByUpdateDateDesc(languageType,"0");
        List<CmsCategoryVO> cmsCategoryVOS=new ArrayList<>();
        for (CmsCategoryEntity cmsCategoryEntity:cmsCategoryEntitieList) {
            CmsCategoryVO cmsCategoryVO = new CmsCategoryVO();
            BeanUtils.copyProperties(cmsCategoryEntity,cmsCategoryVO);
            cmsCategoryVO.setModuleValue(global.getDictValue(StatusCode.DICT_TYPE_CATEGORY_TYPE,cmsCategoryVO.getModule()));
            cmsCategoryVOS.add(cmsCategoryVO);
        }
        return ResultVOUtil.success(cmsCategoryVOS);
    }
}

